#include <iostream>
#include <queue>
using namespace std;

int main()
{
    queue<int> q;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        int input = 0;
        cin >> input;
        switch (input)
        {
        case 1:
            int x;
            cin >> x;
            q.push(x);
            break;
        case 2:
            if (!q.empty()) q.pop();
            else cout << "ERR_CANNOT_POP" << endl;
            break;
        case 3:
            if (!q.empty()) cout << q.front() << endl;
            else cout << "ERR_CANNOT_QUERY" << endl;
            break;
        case 4:
            cout << q.size() << endl;
            break;
        }
    }
    return 0;
}